<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>
<head>
    <meta charset="UTF-8">
	<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <title><?php echo ($meta_title); ?>|OneThink管理平台</title>
    <link href="/M/Public/favicon.ico" type="image/x-icon" rel="shortcut icon">
    <link rel="stylesheet" type="text/css" href="/M/Public/Console/css/base.css" media="all">
    <link rel="stylesheet" type="text/css" href="/M/Public/Console/css/common.css" media="all">
    <link rel="stylesheet" type="text/css" href="/M/Public/Console/css/module.css">
    <link rel="stylesheet" type="text/css" href="/M/Public/Console/css/style.css" media="all">
	<link rel="stylesheet" type="text/css" href="/M/Public/Console/css/<?php echo (C("COLOR_STYLE")); ?>.css" media="all">
	<link rel="stylesheet" type="text/css" href="/M/Public/Console/css/font-awesome.min.css">
     <!--[if lt IE 9]>
    <script type="text/javascript" src="/M/Public/static/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="/M/Public/static/jquery-2.0.3.min.js"></script>
    <![endif]--><!--[if gte IE 9]><!-->
    <script type="text/javascript" src="/M/Public/static/jquery-2.0.3.min.js"></script>
    <!--<![endif]-->
    
</head>
<body>
    <!-- 头部 -->
    <?php $__base_menu__ = $__controller__->getMenus(); ?>
    <div class="header">
        <!-- Logo -->
        <span class="logo"></span>
        <!-- /Logo -->

        <!-- 主导航 -->
        <ul class="main-nav">
            <?php if(is_array($__base_menu__["main"])): $i = 0; $__LIST__ = $__base_menu__["main"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$menu): $mod = ($i % 2 );++$i;?><li class="<?php echo ((isset($menu["class"]) && ($menu["class"] !== ""))?($menu["class"]):''); ?>"><a href="<?php echo (u($menu["url"])); ?>"><?php echo ($menu["title"]); ?></a></li><?php endforeach; endif; else: echo "" ;endif; ?>
        </ul>
        <!-- /主导航 -->

        <!-- 用户栏 -->
        <div class="user-bar">
            <a href="javascript:;" class="user-entrance"><i class="icon-user"></i></a>
            <ul class="nav-list user-menu hidden">
                <li class="manager">你好，<em title="<?php echo session('user_auth.username');?>"><?php echo session('user_auth.username');?></em></li>
                <li><a href="<?php echo U('User/updatePassword');?>">修改密码</a></li>
                <li><a href="<?php echo U('User/updateNickname');?>">修改姓名</a></li>
				<li><a href="<?php echo U('User/profile');?>">个人资料</a></li>
                <li><a href="<?php echo U('Public/logout');?>">退出</a></li>
            </ul>
        </div>
    </div>
    <!-- /头部 -->

    <!-- 边栏 -->
    <div class="sidebar">
        <!-- 子导航 -->
        
            <div id="subnav" class="subnav">
                <?php if(!empty($_extra_menu)): ?>
                    <?php echo extra_menu($_extra_menu,$__base_menu__); endif; ?>

                <?php if(is_array($__base_menu__["child"])): $i = 0; $__LIST__ = $__base_menu__["child"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$sub_menu): $mod = ($i % 2 );++$i;?><!-- 子导航 -->
                    <?php if(!empty($sub_menu)): ?><h3><i class="icon icon-unfold <?php if($currentGroup != $key): ?>icon-fold <?php else: endif; ?> "></i><?php echo ($key); ?></h3>
                        <ul class="side-sub-menu" <?php if($currentGroup != $key): ?>style="display:none" <?php else: endif; ?> >
                            <?php if(is_array($sub_menu)): $i = 0; $__LIST__ = $sub_menu;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$menu): $mod = ($i % 2 );++$i;?><li>
                                    <a class="item" href="<?php echo (u($menu["url"])); ?>"><?php echo ($menu["title"]); ?></a>
                                </li><?php endforeach; endif; else: echo "" ;endif; ?>
                        </ul><?php endif; ?>
                    <!-- /子导航 --><?php endforeach; endif; else: echo "" ;endif; ?>
            </div>
        
        <!-- /子导航 -->
    </div>
    <!-- /边栏 -->

    <!-- 内容区 -->
    <div id="main-content">
        <div id="top-alert" class="fixed alert alert-error" style="display: none;">
            <button class="close fixed" style="margin-top: 4px;">&times;</button>
            <div class="alert-content">这是内容</div>
        </div>
        <div id="main" class="main">
            
            <!-- nav -->
            <?php if(!empty($_show_nav)): ?><div class="breadcrumb">
                <span>您的位置:</span>
                <?php $i = '1'; ?>
                <?php if(is_array($_nav)): foreach($_nav as $k=>$v): if($i == count($_nav)): ?><span><?php echo ($v); ?></span>
                    <?php else: ?>
                    <span><a href="<?php echo ($k); ?>"><?php echo ($v); ?></a>&gt;</span><?php endif; ?>
                    <?php $i = $i+1; endforeach; endif; ?>
            </div><?php endif; ?>
            <!-- nav -->
            

            
	<!-- 标题栏 -->
	<div class="main-title">
		<h2>在线打卡</h2>
	</div>
	<div class="cf">
		<div class="fl">
            <button class="btn ajax-post confirm" url="<?php echo U('Attendence/changeStatus',array('method'=>'deleteUser'));?>" target-form="ids">删 除</button>
			<button class="btn run-time" style="background:#CE1961;display:none;"></button>
        </div>
		<!-- 高级搜索 -->
		<div class="search-form fr cf">
			<div class="sleft">
				<div class="drop-down">
					<span id="sch-sort-txt" class="sort-txt" data="<?php echo ($status); ?>"><?php if(get_status_title($status) == ''): ?>所有<?php else: echo get_status_title($status); endif; ?></span>
					<i class="arrow arrow-down"></i>
					<ul id="sub-sch-menu" class="nav-list hidden">
						<li><a href="javascript:;" value="">所有</a></li>
						<li><a href="javascript:;" value="1">迟到</a></li>
					</ul>
				</div>
				<input type="text" name="uid" class="search-input" value="<?php echo I('uid');?>" placeholder="请输入用户UID">
				<a class="sch-btn" href="javascript:;" id="search" url="<?php echo U();?>"><i class="btn-search"></i></a>
			</div>
            <div class="btn-group-click adv-sch-pannel fl">
                <button class="btn">高 级<i class="btn-arrowdown"></i></button>
                <div class="dropdown cf">
                	<div class="row">
                		<label>更新时间：</label>
                		<input type="text" id="time-start" name="time-start" class="text input-2x" value="" placeholder="起始时间" /> -
                		<input type="text" id="time-end" name="time-end" class="text input-2x" value="" placeholder="结束时间" />
                	</div>
                	
                </div>
            </div>
		</div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table class="">
			<thead>
				<tr>
					<th class="row-selected row-selected"><input class="check-all" type="checkbox"></th>
					<th class="">UID</th>
					<th class="">姓名</th>
					<th class="">职位</th>
					<th class="">部门</th>
					
					<th class="">状态</th>
					<th class="">签到时间</th> 
					<th class="">签退时间</th> 
					<th class="">操作</th> 
				</tr>
			</thead>
			<tbody>
			<?php if(is_array($list)): $i = 0; $__LIST__ = $list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr>
					<td><input class="ids" type="checkbox" name="id[]" value="3"></td>
					<td><?php echo ($vo["uid"]); ?></td>
					<td><?php echo ($vo["nickname"]); ?></td>
					<td><?php echo ($vo["position"]); ?></td>
					<td><?php echo ($vo["department"]); ?></td>
					<td><?php echo ($vo["status_txt"]); ?></td>
					<td><input type="text" class="text <?php echo (not_exist($vo["attendence_time"],attendence_time)); ?>" id="attendence-<?php echo ($vo["uid"]); ?>" name="attendence_time" data-format="hh:mm:ss" value="<?php echo (datetime($vo["attendence_time"])); ?>" data-url="<?php echo U('makeRecord?uid='.$vo['uid']);?>"></td>
					<td><input type="text" class="text <?php echo (not_exist($vo["absence_time"],absence_time)); ?>" id="absence-<?php echo ($vo["uid"]); ?>" name="absence_time" data-format="hh:mm:ss" value="<?php echo (datetime($vo["absence_time"])); ?>" data-url="<?php echo U('makeRecord?uid='.$vo['uid']);?>"></td>
					<td>
						<button class="btn btn-success btn-attendence" data-id="<?php echo ($vo["uid"]); ?>" url="<?php echo U('Attendence/makeRecord',array('uid'=>$vo[uid],'type'=>1));?>" >签到</button>
						<button class="btn btn-warn btn-absence" data-id="<?php echo ($vo["uid"]); ?>" url="<?php echo U('Attendence/makeRecord',array('uid'=>$vo[uid],'type'=>2));?>" >签退</button>
					</td>
				</tr><?php endforeach; endif; else: echo "" ;endif; ?>
			</tbody>
		</table>
	</div>
    <div class="page">
        <?php echo ($_page); ?>
    </div>

        </div>
        <div class="cont-ft">
            <div class="copyright">
                <div class="fl">感谢使用<a href="http://www.onethink.cn" target="_blank">OneThink</a>管理平台</div>
                <div class="fr">V<?php echo (ONETHINK_VERSION); ?></div>
            </div>
        </div>
    </div>
    <!-- /内容区 -->
    <script type="text/javascript">
    (function(){
        var ThinkPHP = window.Think = {
            "ROOT"   : "/M", //当前网站地址
            "APP"    : "/M/index.php?s=", //当前项目地址
            "PUBLIC" : "/M/Public", //项目公共目录地址
            "DEEP"   : "<?php echo C('URL_PATHINFO_DEPR');?>", //PATHINFO分割符
            "MODEL"  : ["<?php echo C('URL_MODEL');?>", "<?php echo C('URL_CASE_INSENSITIVE');?>", "<?php echo C('URL_HTML_SUFFIX');?>"],
            "VAR"    : ["<?php echo C('VAR_MODULE');?>", "<?php echo C('VAR_CONTROLLER');?>", "<?php echo C('VAR_ACTION');?>"]
        }
    })();
    </script>
    <script type="text/javascript" src="/M/Public/static/think.js"></script>
    <script type="text/javascript" src="/M/Public/Console/js/common.js"></script>
    <script type="text/javascript">
        +function(){
            var $window = $(window), $subnav = $("#subnav"), url;
            $window.resize(function(){
                $("#main").css("min-height", $window.height() - 130);
            }).resize();

            /* 左边菜单高亮 */
            url = window.location.pathname + window.location.search;
            $subnav.find("a[href='" + url + "']").parent().addClass("current");

            /* 左边菜单显示收起 */
            $("#subnav").on("click", "h3", function(){
                var $this = $(this);
                $this.find(".icon").toggleClass("icon-fold");
                $this.next().slideToggle("fast").siblings(".side-sub-menu:visible").
                      prev("h3").find("i").addClass("icon-fold").end().end().hide();
            });

            $("#subnav h3 a").click(function(e){e.stopPropagation()});

            /* 头部管理员菜单 */
            $(".user-bar").mouseenter(function(){
                var userMenu = $(this).children(".user-menu ");
                userMenu.removeClass("hidden");
                clearTimeout(userMenu.data("timeout"));
            }).mouseleave(function(){
                var userMenu = $(this).children(".user-menu");
                userMenu.data("timeout") && clearTimeout(userMenu.data("timeout"));
                userMenu.data("timeout", setTimeout(function(){userMenu.addClass("hidden")}, 100));
            });

	        /* 表单获取焦点变色 */
	        $("form").on("focus", "input", function(){
		        $(this).addClass('focus');
	        }).on("blur","input",function(){
				        $(this).removeClass('focus');
			        });
		    $("form").on("focus", "textarea", function(){
			    $(this).closest('label').addClass('focus');
		    }).on("blur","textarea",function(){
					    $(this).closest('label').removeClass('focus');
				    });
        }();
    </script>
    
	<script src="/M/Public/static/thinkbox/jquery.thinkbox.js"></script>
	<?php echo '<link href="/M/Public/static/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">'; ?>
	<link href="/M/Public/static/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">

	<script type="text/javascript" src="/M/Public/static/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
	<script type="text/javascript" src="/M/Public/static/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>

	<script type="text/javascript">
	//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
		var status = $("#sch-sort-txt").attr("data");
		var search = $('input[name=uid]').val();
		if(status != ''){
			url += '/status/' + status;
		}
		if(search != ''){
			url += '/uid/' + encodeURIComponent(search);
		}
		window.location.href = url;
	});
	/* 高级搜索子菜单 */
	$(".search-form").find(".drop-down").hover(function(){
		$("#sub-sch-menu").removeClass("hidden");
	},function(){
		$("#sub-sch-menu").addClass("hidden");
	});
	$("#sub-sch-menu li").find("a").each(function(){
		$(this).click(function(){
			var text = $(this).text();
			$("#sch-sort-txt").text(text).attr("data",$(this).attr("value"));
			$("#sub-sch-menu").addClass("hidden");
		})
	});
    //导航高亮
    $('.side-sub-menu').find('a[href="<?php echo U('User/index');?>"]').closest('li').addClass('current');
	$(function(){
		$('.attendence_time').datetimepicker({
		  pickDate: false
		});
		
		$('.attendence_time').bind('input propertychange', function() {
			alert('start');
			if($(this).val() != ''){
				alert('start');
				var url = $(this).attr('data-url');
				var time = $(this).val();
				$.getJSON(url,{attendence_time:time},function(json){
					if(json.status == 1){
						alert('success');
					}else{
						alert('fail');
					}
				});
			}else{
				alert('q12');
			}
		});
		setInterval(function(){
			var date = new Date();
			var time = date.format("yyyy-MM-dd hh:mm:ss"); 
			$('.run-time').html(time);
			$('.run-time').show();
			$('.attendence_time').val(time);
			$('.absence_time').val(time);
			
		},1000);

		 //自动签到
		$('.btn-attendence').click(function(){
			var target;
			var that = this;
			var data_id =  $(this).attr('data-id');
			if ( $(this).hasClass('confirm') ) {
				if(!confirm('确认要执行该操作吗?')){
					return false;
				}
			}
			if(!$('#absence-'+data_id).hasClass('absence_time')){
				updateAlert("已经签退，不能签到");
				setTimeout(function(){
					$('#top-alert').find('button').click();
					
				},1500);
				return;
			}
			if(!$('#attendence-'+data_id).hasClass('attendence_time')){
				updateAlert('已经签到，不能再次签到');
				setTimeout(function(){
					$('#top-alert').find('button').click();
					
				},1500);
				return;
			}
			if ( (target = $(this).attr('href')) || (target = $(this).attr('url')) ) {
				$.get(target).success(function(data){
					if (data.status==1) {
						//这里当前用户签到时间计时
						    $('#attendence-'+data_id).removeClass('attendence_time');
							$('#absence-'+data_id).addClass('absence_time');
						    console.log(data_id);
							updateAlert(data.info,'alert-success');
						
						setTimeout(function(){
							$('#top-alert').find('button').click();
							
						},1500);
					}else{
						updateAlert(data.info);
						setTimeout(function(){
							$('#top-alert').find('button').click();
							
						},1500);
					}
				});

			}
			return false;
		});
		 //自动签退
		$('.btn-absence').click(function(){
			var target;
			var that = this;
			var data_id =  $(this).attr('data-id');
			if ( $(this).hasClass('confirm') ) {
				if(!confirm('确认要执行该操作吗?')){
					return false;
				}
			}
			if($('#attendence-'+data_id).hasClass('attendence_time')){
				updateAlert('未签到，不能签退');
				setTimeout(function(){
					$('#top-alert').find('button').click();
					
				},1500);
				return;
			}
			if(!$('#absence-'+data_id).hasClass('absence_time')){
				updateAlert('已经签退，不能再次签退');
				setTimeout(function(){
					$('#top-alert').find('button').click();
					
				},1500);
				return;
			}
			if ( (target = $(this).attr('href')) || (target = $(this).attr('url')) ) {
				$.get(target).success(function(data){
					if (data.status==1) {
						//移除签退时间计时
							$('#absence-'+data_id).removeClass('absence_time');
							updateAlert(data.info,'alert-success');
						
						setTimeout(function(){
							$('#top-alert').find('button').click();
							
						},1500);
					}else{
						updateAlert(data.info);
						setTimeout(function(){
							$('#top-alert').find('button').click();
							
						},1500);
					}
				});

			}
			return false;
		});
		
	});
	</script>

</body>
</html>